package com.ggkt.common.utils.web;
/**

 * @author ggkt
 */
public class RestResult {
    
    /**
     * 	状态码
     */
    private int code;
    
    /**
     * 	相应消息
     */
    private String message;
    
    private Object data;
    
    public RestResult() {
        super();
    }

    public RestResult(int code, String msg, Object data) {
        super();
        this.code = code;
        this.message = msg;
        this.data = data;
    }
    
    public RestResult(RestStatus status, Object data) {
        super();
        this.code = status.status();
        this.message = status.msg();
        this.data = data;
    }
    
    public static RestResult success(Object data) {
        return create(data, RestStatus.Success);
    }
    
    public static RestResult success() {
        return success("");
    }
    
    public static RestResult paramError() {
        return create(RestStatus.ParamError);
    }
    
    public static RestResult signError() {
        return create(RestStatus.SignError);
    }

    public static RestResult error(String msg) {
        return new RestResult(RestStatus.Error.status(), msg, null);
    }
    
    public static RestResult error() {
        return create(RestStatus.Error);
    }
    
    public static RestResult fail() {
        return create(RestStatus.Fail);
    }
    
    public static RestResult create(Object data, RestStatus status) {
        return new RestResult(status, data);
    }
    
    public static RestResult create(RestStatus status) {
        return new RestResult(status, null);
    }
    
    public boolean isSuccess() {
    	return this.code == RestStatus.Success.status();
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }


    public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
